<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.2</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="./css/font.css">
    <link rel="stylesheet" href="./css/xadmin.css">
    <script type="text/javascript" src="./lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="./js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row">

        <form  method="post" enctype="multipart/form-data" action="/"  class="layui-form">
            <div class="layui-form-item">
                <label for="user_name" class="layui-form-label">
                    <span class="x-red">*</span>用户的姓名
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="user_name" name="user_name" required="" lay-verify="required"
                           autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>添加姓名
                </div>
            </div>


            <div class="layui-form-item">
                <label for="user_personal" class="layui-form-label">
                    <span class="x-red">*</span>个人照
                </label>
                <div class="layui-input-inline">
                    <input type="file" id="user_personal" name="user_personal" required="" lay-verify="required"
                           autocomplete="off" class="layui-upload-file">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>上传自己的个人照片
                </div>
            </div>


            <div class="layui-form-item">
                <label for="user_card" class="layui-form-label">
                    <span class="x-red">*</span>身份证号
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="user_card" name="user_card" required="" lay-verify="required"
                           autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>
                </div>
            </div>

            <div class="layui-form-item">
                <label for="user_head" class="layui-form-label">
                    <span class="x-red">*</span>头像
                </label>
                <div class="layui-input-inline">
                    <input type="file" id="user_head" name="user_head" required="" lay-verify="required"
                           autocomplete="off" class="layui-upload-file">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>上传自己的头像
                </div>
            </div>

            <div class="layui-form-item">
                <label for="journalism_content3" class="layui-form-label">
                    <span class="x-red">*</span>手机号
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="journalism_content3" name="journalism_content3" required="" lay-verify="required"
                           autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>输入手机号
                </div>
            </div>

            <div class="layui-form-item">
                <label for="user_password" class="layui-form-label">
                    <span class="x-red">*</span>密码
                </label>
                <div class="layui-input-inline">
                    <input type="password" id="user_password" name="user_password" required="" lay-verify="required"
                           autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                   请输入密码
                </div>
            </div>

            <div class="layui-form-item">
                <label for="journalism_remarks" class="layui-form-label">
                    <span class="x-red">*</span> 备注
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="journalism_remarks" name="journalism_remarks" required="" lay-verify=""
                           autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>
                </div>
            </div>

            <div class="layui-form-item">
                <label for="journalism_s" class="layui-form-label">
                    <span class="x-red">*</span>说明
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="journalism_s" name="journalism_s" required="" lay-verify=""
                           autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>
                </div>
            </div>

            <div class="layui-form-item">
                <label for="journalism_s" class="layui-form-label">
                </label>
                <button  class="layui-btn" lay-filter="add" lay-submit="">
                    增加
                </button>
            </div>
        </form>
    </div>
</div>
<script>layui.use(['form', 'layer'],
    function() {
        $ = layui.jquery;
        var form = layui.form,
            layer = layui.layer;

        //自定义验证规则
        form.verify({
            nikename: function(value) {
                if (value.length < 5) {
                    return '昵称至少得5个字符啊';
                }
            },
            pass: [/(.+){6,12}$/, '密码必须6到12位'],
            repass: function(value) {
                if ($('#L_pass').val() != $('#L_repass').val()) {
                    return '两次密码不一致';
                }
            }
        });

        //监听提交
        form.on('submit(add)',
            function(data) {
                console.log(data);
                var fordata = new FormData();
                fordata.append('journalism_title',$('#journalism_title').val());
                fordata.append('journalism_content2',$('#journalism_content2').val());
                fordata.append('journalism_content3',$('#journalism_content3').val());
                fordata.append('journalism_state',$('#journalism_state').val());
                fordata.append('journalism_remarks',$('#journalism_remarks').val());
                fordata.append('journalism_s',$('#journalism_s').val());
                fordata.append('journalism_content1',$('#journalism_content1')[0].files[0]);

                $.ajax({
                    type:"post",
                    url:"/insertjournalism",
                    processData: false,
                    contentType: false,
                    cache:false,
                    async: false,
                    data:fordata,
                    success:function(data) {
                        console.log(data);
                        if(data.status==401){
                            alert("熔断开启，系统异常");
                            window.location.href="login.html";
                            return;
                        }
                        if(data.status==200) {
                            layer.alert("添加成功", {icon: 8},function () {
                                var index=parent.layer.getFrameIndex(window.name);//获取当前弹出层的层级
                                window.parent.location.reload();//刷新父页面
                                parent.layer.close(index);//关闭弹出层
                            });
                            return;
                        }
                        if(data.status==500) {
                            alert("添加错误");
                            window.location.href="adminlist.html";
                            return;
                        }
                        if(data.status==null) {
                            alert("修改异常");
                            window.location.href="adminlist.html";
                            return;
                        }
                        if(data.status==20) {
                            layer.alert("重复添加", {icon: 3},function () {
                                var index=parent.layer.getFrameIndex(window.name);//获取当前弹出层的层级
                                parent.layer.reload(index);
                            });
                            return;
                        }
                    }
                });
                return false;
            });

    });
</script>

</body>

</html>
